package project.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import project.Dto.QuestionDto;
import project.Pojo.Result;
import project.Service.Impl.QuestionServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    QuestionServiceImpl questionService;

    @GetMapping("createquestionnaire")
    public Result createQuestionnaire() {
        List<QuestionDto> questionnaire = questionService.createQuestionnaire();
        List<Map<String, Object>> qusmap = new ArrayList<>();
        for (QuestionDto questionDto : questionnaire) {
            Map<String, Object> map = new HashMap<>();
            map.put("qId", questionDto.getQId());
            map.put("question", questionDto.getQuestion());
            qusmap.add(map);
        }

        return new Result(200, "调查问卷生成成功", qusmap);
    }
}
